package top.yqingyu.trans$client.cs.command;

import top.yqingyu.qymsg.QyMsg;
import top.yqingyu.trans$client.api.Connection;
import top.yqingyu.trans$client.main.TransClient;

/**
 * @author YYJ
 * @version 1.0.0
 * @date 2022/4/23 22:44
 * @description 所有的命令都必须实现本接口
 * @modified by
 */
public abstract class Command {


    /**
     * <p>
     * socketChannel.register(selector, SelectionKey.OP_READ);
     * description: 命令处理方法
     *
     * @author yqingyu
     * DATE 2022/4/24
     */
    public abstract void deal(QyMsg msg, TransClient client) throws Exception;


    public void dealCommand(TransClient client, Connection connection, QyMsg msg) throws Exception {
        writeDeal(client, connection, msg);
    }

    protected final void dealWrite(TransClient client, Connection connection, QyMsg msg) throws Exception {
        deal(msg, client);
        connection.send(msg);
    }

    protected final void writeDeal(TransClient client, Connection connection, QyMsg msg) throws Exception {
        connection.send(msg);
        deal(msg, client);
    }


}
